<?php 
class Login extends CI_Controller {

var $msg;
	public function __construct()
	{
		parent::__construct();
		//$this->load->model('sysuser_model');
		$this->load->library('sys/sysuser');
	}

	public function index()
	{
	
	
	//print(APPPATH);
	//$data['news'] = $this->news_model->get_news();
	//$this->load->view('templates/header',$data);
	//$this->load->view('templates/footer',$data);
		$this->load->view('scp/vwlogin');
	}


	function verify($uid,$pass)
	{
		$cuser= new SysUser($uid);	
		if($cuser)	 {	
			if(!$cuser->islocked){
				 if($rslt=$cuser->verifyuserpassword($uid,$pass)){
					$this->session->set_userdata('logged_in', $rslt);				
					return true;
				 }
				 else{
					$cuser->IncErrorCount();
				 }
			}
			else{
				$this->msg='Your ID has been Locked';				
			}
		}
		return true;
	}

	public function submit()
	{
	    $uname = $this->input->post('username');
		$pwd = $this->input->post('password');
		if($this->verify($uname,$pwd)){
			redirect('','refresh');							
		}
		else{		
			$data['msg']=$this->msg;
			$this->load->view('scp/vwlogin', $data);	
		}  
	}

	public function logout()
	{
		$this->session->unset_userdata('logged_in');
			redirect('','refresh');		
	}

  }